//
//  SC_Search_PartyCell.swift
//  APSwift
//
//  Created by jianbo.pei on 2023/4/25.
//

import UIKit
import SnapKit
import Then

class SC_Search_PartyCell: APBaseTableViewCell {
    ///封面
    private var coverImageView = UIImageView()
    ///房间ID
    private var roomIDLabel = UILabel()
    ///房间名称
    private var roomNameLabel = UILabel()
    
    override func initUI() {
        super.initUI()
        
        backgroundColor = .clear
        contentView.addSubview(coverImageView)
        coverImageView.layer.cornerRadius = 10
        coverImageView.layer.masksToBounds = true
        
        coverImageView.addSubview(roomIDLabel)
        coverImageView.addSubview(roomNameLabel)
    }
    
    override func makeConstraints() {
        super.makeConstraints()
        
        coverImageView.snp.makeConstraints { make in
            make.left.equalTo(10)
            make.right.bottom.equalTo(-10)
            make.top.equalToSuperview()
        }
        
        roomIDLabel.snp.makeConstraints { make in
            make.left.equalTo(12)
            make.bottom.equalTo(-15)
            make.height.equalTo(18)
        }
        
        roomNameLabel.snp.makeConstraints { make in
            make.left.equalTo(12)
            make.bottom.equalTo(roomIDLabel.snp.top).offset(-2)
        }
    }
    
    override func setup(_ model: Any?) {
        guard let model = model as? SC_Search_RoomModel else { return }
        if let gif_cover2 = model.gif_cover2, !gif_cover2.isEmpty {
            coverImageView.kf.setImage(with: URL(string: gif_cover2))
        } else if let cover2 = model.cover2, !cover2.isEmpty {
            coverImageView.kf.setImage(with: URL(string: cover2))
        } else if let cover = model.cover, !cover.isEmpty {
            coverImageView.kf.setImage(with: URL(string: cover))
        }
        
        if let id = model.id, id > 0 {
            roomIDLabel.text = "ID：\(id)"
        } else {
            roomIDLabel.text = nil
        }
        roomNameLabel.text = model.title

    }
}

extension SC_Search_PartyCell: APView_Height_Protocol {
    static func viewHeight(with model: Any?) -> CGFloat {
        return 140
    }
}
